/*
 * common_options.hpp
 *
 *  Created on: Jul 28, 2010
 *      Author: sdaniele
 */

#ifndef COMMON_OPTIONS_HPP_
#define COMMON_OPTIONS_HPP_

#include "systemc.h"
#include <boost/program_options.hpp>
#include <iostream>
namespace po = boost::program_options;

namespace syscpar{namespace test{


class common_options {

public:
	common_options()
		:m_sim_time(0),m_asked_help(false),m_verbose(false),m_use_threads(false)
	{}
	~common_options(){
		if(m_sim_time)
			delete m_sim_time;
	}

public:
	void parse( int argc, char** argv, std::ostream& out = std::cout ){

		double sim_time;

		//declare options
		po::options_description desc("Common options");
		desc.add_options()
		    ("help", 																		"produce help message")
		    ("verbose,v",			po::bool_switch(&m_verbose), 							"verbose")
		    ("use-threads,t",		po::bool_switch(&m_use_threads), 						"whether to use threads (or methods otherwise)")
		    ("sim-time,s",			po::value<double>(&sim_time),							"simulation time, in ms")

		;

		//invoke args parser
		po::variables_map vm;
		po::store(po::parse_command_line(argc, argv, desc), vm);
		po::notify(vm);

		if (vm.count("help")) {
			out << desc << "\n";
			m_asked_help = true;
			return;
		}

		if(vm.count("sim-time"))
			m_sim_time = new sc_time(sim_time,SC_MS);
	}


public:
	const bool use_threads() const {
		return m_use_threads;
	}

	const bool asked_help() const {
		return m_asked_help;
	}

	const bool verbose() const {
		return m_verbose;
	}

	const sc_time* sim_time() const {		//NULL if not set
		return m_sim_time;
	}

private:
	bool m_asked_help;
	bool m_verbose;
	bool m_use_threads;
	sc_time* m_sim_time;
};


}}

#endif /* COMMON_OPTIONS_HPP_ */
